#include "registerform.h"
#include "ui_registerform.h"
#include "QMessageBox"

RegisterForm::RegisterForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RegisterForm)
{
    ui->setupUi(this);
}

RegisterForm::~RegisterForm()
{
    delete ui;
}

void RegisterForm::on_pushButton_clicked()
{
    if (ui->le_name->text().isEmpty())
    {
        QMessageBox::warning(this, "警告", "名字不能为空!",
                             QMessageBox::Retry|QMessageBox::Close);
    }else if(ui->le_id->text().isEmpty())
    {
        QMessageBox::warning(this, "警告", "账号不能为空!",
                             QMessageBox::Retry|QMessageBox::Close);
    }else if(ui->le_pswd->text().isEmpty())
    {
        QMessageBox::warning(this, "警告", "密码不能为空!",
                             QMessageBox::Retry|QMessageBox::Close);
    }else if(ui->le_confirmpswd->text().isEmpty())
    {
        QMessageBox::warning(this, "警告", "确认密码不能为空!",
                             QMessageBox::Retry|QMessageBox::Close);
    }else
    {
        if (ui->le_pswd->text() == ui->le_confirmpswd->text())
        {
            UserInfo info(ui->le_id->text(),
                          ui->le_name->text(),
                          ui->le_pswd->text());

            emit signalUserRegiter(info);
        }else
        {
            QMessageBox::warning(this, "警告", "两次密码不一样!",
                                 QMessageBox::Retry|QMessageBox::Close);
        }
    }
}

void RegisterForm::on_pb_return_clicked()
{
    emit signalReturn();
}
